class PathTree{
  Node root;
  PathTree(){
    
  }
  void addTriangle(int triIndex){
    addTriangle(root,triIndex);
  }
  void addTriangle(Node root, int triIndex){
    if(root == null){
      root = new Node(triIndex);
    } else {
      if(root.nextLeft == null){
        root.nextLeft = new Node(triIndex);
      } else if(root.nextRight == null) {
        root.nextRight = new Node(triIndex);
      } else if(root.nextRight.children < root.nextLeft.children){
        addTriangle(root.nextRight,triIndex);
      } else {
        addTriangle(root.nextLeft,triIndex);
      }
      root.children++;
    }
    
  }
  
}

class Node{
  Node nextLeft;
  Node nextRight;
  int triIndex;
  int children = 0;
  Node(int index){
    triIndex = index;
  }
}
